﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace NIP.Speech.Dialog.States
{
    public class IdleDialogState: DialogStateBase, IDialogState 
    {
        //public event EventHandler<EventArgs.StateStatusEventArgs> StateStatusChanged;


        public IdleDialogState():base(DialogStateType.IdleDialogState)
        {
            
        }

        new public bool PreConditionCheck()
        {
            return true;
        }

        new public EventArgs.StateStatusEventArgs VoiceCommandResponse(Dictionary<string, string> recognizedText)
        {
            var args = new EventArgs.StateStatusEventArgs();
            string greeting = "";
            string name = "";
            if(recognizedText.ContainsKey("greeting"))
            {
                greeting = recognizedText["greeting"];
                args.Type = EventArgs.StateStatusEventTypes.ACTION_REQUESTED;
            }
            if (recognizedText.ContainsKey("robotname"))
            {
                name = recognizedText["robotname"];

                args.Type = EventArgs.StateStatusEventTypes.ACTION_REQUESTED;
            }
            else name = "Mary";

            StateStatus.RobotName = name;
            args.CommandString += greeting + " " + name;

            // if neither was received, unchanged, else move on
            if (args.Type != EventArgs.StateStatusEventTypes.NONE)
            {
                args.ActionRequested = "hello";
                args.ToSpeak += (greeting == "" ? "Good day! " : greeting);
                args.ToSpeak += " My name is ";
                args.ToSpeak += name;
                args.ToSpeak += " nice to meet you. Would you like to learn how to use the robot? ";
                args.nextState = Responder.StateCreator(DialogStateType.QueryDialogState);
                args.nextState.para.configCommand.Add("if_yes", "help");
                args.nextState.para.configCommand.Add("if_no", "none");
                args.nextState.DefaultAbortNextState = DialogStateType.SessionAwaitingCommandDialogState;
                args.nextState.DefaultNextState = DialogStateType.SessionAwaitingCommandDialogState;
                args.nextState.DefaultSpeechResponse += " . Yes or No ? ";
            }
            else
            {
                args.Type = EventArgs.StateStatusEventTypes.SPEAK_ONLY;
                args.ToSpeak = DefaultSpeechResponse;
            }
            return args;
        }

        new public EventArgs.StateStatusEventArgs VoiceCommandResponse(string recognizedString)
        {
            throw new NotImplementedException();
        //    var args = new EventArgs.StateStatusEventArgs(); 
        //    args.CommandString = recognizedString;
        //    var index = recognizedString.ToLower().IndexOf("hello");
        //    if ( index >= 0)
        //    {
        //        //! Initiate Session
        //        args.Type = EventArgs.StateStatusEventTypes.SPEAK_ONLY;
        //        args.ToSpeak = "Good day! My name is Mary, nice to meet you. Would you like to know more about what I can do?";
                
        //        //args.NextState = DialogStateType.SessionAwaitingCommandDialogState;
                
        //    }
        //    return args;
        }

        
        
    }
}
